package API.DateDome.LocalDateTimeDome;

import java.time.LocalDate;
import java.time.Period;

/**
 * ClassName:LocalDateTimeText006
 * Package:API.DateDome.LocalDateTimeDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/2-19:27
 * @Version:v1.0
 */
public class PeriodDome {
    /*
    * ------工具类------
    * Duration   用于计算连个时间间隔(秒,纳秒)
    * Period  用于计算两个日期间隔(年月日)
    * ChronoUnit 用来计算两个日期间隔
    * */
    public static void main(String[] args) {
        //当前本地 年月日
        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);

        //生日的 年月日
        LocalDate birthDate = localDate.of(2000,04,04);
        System.out.println(birthDate);

        Period period = Period.between(birthDate,localDate);//第二个参数减第一个参数

        System.out.println("相差的时间间隔对象："+period);
        System.out.println(period.getYears());
        System.out.println(period.getMonths());
        System.out.println(period.getDays());

        System.out.println("相差"+period.toTotalMonths()+"个月");
    }
}
